package com.dg.river.module.common.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.dg.river.databinding.ActivityShowFullImageBinding;
import com.dg.river.module.base.BaseActivity;
import com.dg.river.module.common.adapter.SamplePagerAdapter;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;

import java.io.Serializable;
import java.util.List;

/**
 * @作者：HuYong
 * @时间：2023/4/12 16:19
 * @描述：看大图
 * @xml：activity_show_full_image.xml
 * @修改：
 */
public class ShowFullImageActivity extends BaseActivity {

    private ActivityShowFullImageBinding binding;
    private ImmersionBar immersionBar;
    private List<String> list;
    private int position;
    private RequestManager glide;

    private SamplePagerAdapter adapter;

    private static final String IMG_LIST = "imgList";
    private static final String POSITION = "position";

    public static void start(Context mContext, List<String> imageList, int position) {
        Intent intent = new Intent(mContext, ShowFullImageActivity.class);
        intent.putExtra(IMG_LIST, (Serializable) imageList);
        intent.putExtra(POSITION, position);
        mContext.startActivity(intent);
    }

    @Override
    public View initLayout() {
        binding = ActivityShowFullImageBinding.inflate(getLayoutInflater());
        return binding.getRoot();
    }

    @Override
    protected void initGetIntent() {
        super.initGetIntent();
        list = (List<String>) getIntent().getSerializableExtra(IMG_LIST);
        position = getIntent().getIntExtra("position", 0);
    }

    @Override
    public void initView() {
        //隐藏底部导航
        ImmersionBar.with(this).hideBar(BarHide.FLAG_HIDE_BAR).init();

        glide = Glide.with(this);

        adapter = new SamplePagerAdapter(list, glide);
        binding.viewpagerImageshow.setAdapter(adapter);
        if (position != 0) {
            binding.viewpagerImageshow.setCurrentItem(position);
        } else {
            binding.viewpagerImageshow.setCurrentItem(0);
        }
    }

    @Override
    public boolean viewAndData() {
        return true;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {
        binding.viewpagerImageshow.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                binding.chooseNumText.setText(String.format("%d/%d", position + 1, list.size()));
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        adapter.setOnItemClickLitener(view -> finish());

        binding.rlMain.setOnClickListener(view -> finish());
    }

    @Override
    public void showErrorMessage(@Nullable String message) {

    }
}
